using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using Common.Enum;

namespace Converters
{
	public class PropertyMultiConverter : IMultiValueConverter
	{
		public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			if (values.Count() == 2 && values[0] != null && values[0] != DependencyProperty.UnsetValue && values[0] is SampleType && values[1] != null && values[1] != DependencyProperty.UnsetValue)
			{
				SampleType sampleType = (SampleType)values[0];
				if (sampleType == SampleType.Standard)
				{
					double result = 0.0;
					if (double.TryParse(values[1].ToString(), out result))
					{
						if (parameter == null)
						{
							return result.ToString("#,#");
						}
						return result.ToString("0.000E0");
					}
				}
			}
			return values[1];
		}

		public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
		{
			return null;
		}
	}
}
